<template>
	<om-formsub-outer :index="index" :checkedit="checkedit">
		<om-autoform ref="autoform" :initConfigData="autoformdata" :initValue="initValue"></om-autoform>
	</om-formsub-outer>
</template>

<script>
	const app = getApp();
	import {buildSubFormData, subOnLoad, changeEditor,configSelectData,hasValue} from '@/static/js/formUtil.js';
	import { ignoreHtml,ptFloat,minusF,getDateStr} from '@/static/js/common.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildSubFormData({
				formdata:{},
				initValue:{},
				autoformdata: [],
				index: null,
				orderNumCacheKey:'customer-contact-user-cache'
			})
		},
		methods:{
			async verifySubConfirm(){
				let _that = this
				return new Promise((resolve,reject)=>{
					uni.request({
						url:app.globalData.url+"customer/phoneCheck.do?phone="+_that.$refs.autoform.formdata.phone+'&userName='+this.$refs.autoform.formdata.userName,
						method:"post",
						success:(res)=>{
								if (res.data[0].id === '90036') {
									this.$refs.autoform.$set(this.$refs.autoform.formdata,'identification','1')
								} else if (res.data[0].id === '90035') {
									this.om.toast('该手机号是在职人员，请重新输入手机号码')
								} else if (res.data[0].id === '90034') {
									this.om.toast('联系人姓名不同，请重新输入手机号码')
								} else if (res.data[0].id === '90033') {
									confirmModal(this, '提示信息', '请确认输入手机号码与联系人为同一人', confirm => {
										this.$refs.autoform.$set(this.$refs.autoform.formdata,'identification','3')
									},cancel => {
										this.$refs.autoform.formdata.phone = ''
										this.$refs.autoform.$set(this.$refs.autoform.formdata,'identification','')
									})
								} else if (res.data[0].id === '90032') {
									confirmModal(this, '提示信息', '是否使用该手机号', confirm => {
										this.$refs.autoform.formdata.identification = '1'
									},cancel => {
										this.$refs.autoform.formdata.phone = ''
										this.$refs.autoform.formdata.identification = ''
									})
								}
							resolve(true)
						}
					})
				})
			},
			initLoad(){
				let _that = this
				let arr = [
					_that.om.request(
						"customer/getCustomer",
						{
							code:'39113'
						}
					),
					_that.om.request(
						"dictZero/getListByCode",
						{
							code:'23591'
						}
					),
					_that.om.request(
						"customer/getCustomer",
						{
							code:'39013'
						}
					)
					
				] 
				Promise.all(arr).then(res=>{
					_that.$refs.autoform.changeEditor('title2','roleId','data',configSelectData(res[0],'id','dicname'))
					_that.$refs.autoform.initSelectIndex('title2','roleId')
					_that.$refs.autoform.changeEditor('title2','sexCode','data',configSelectData(res[1],'code','dicname'))
					_that.$refs.autoform.initSelectIndex('title2','sexCode')
					_that.$refs.autoform.changeEditor('title2','postTypeId','data',configSelectData(res[2],'id','dicname'))
					_that.$refs.autoform.initSelectIndex('title2','postTypeId')
				})
			},
			inputPhone(e) {
				
			}
		},
		onShow() {
			
		},
		onLoad(e) {
			let _that = this
			subOnLoad(_that, e, function() {
			if(e.configDataCacheKey){
				uni.getStorage({
					key: e.configDataCacheKey,
					success: function(res) {
						if(res.data && Object.prototype.toString.call(res.data)==='[object Array]'){
							_that.autoformdata = res.data
							Object.assign(_that.initValue, _that.formdata)
							_that.autoformdata[0].order = _that.order
							_that.initLoad()
							}
						}
					})
				}
			})
		}
	}
</script>

<style>
</style>